n, k  = map(int, input().split())
nums = list(map(int, input().split()))
array = [0] * n
for i in range(n):
    array[i] = nums[i] ** 2
array.sort()
ans = float('inf')
for i in range(n- k + 1):
    ans = min(array[i+k-1] - array[i],ans)
print(ans)